package com.ejoysoft.wirelessnet.warehousing;

import java.io.*;
import java.util.*;  

import org.w3c.dom.*;  
import javax.xml.parsers.*;

import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import com.ejoysoft.common.*;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ReadXML
{
	private Globa globa =new Globa();
    private DbConnect dd = new DbConnect();
    
	public ReadXML(){} 
	public ReadXML(Globa globa) {
        this.globa = globa;
        dd = globa.db;
    }
	
	public ReadXML(Globa globa, boolean b) {
        this.globa = globa;
        dd = globa.db;
        if (b) globa.setDynamicProperty(this);
    }
	
	public String returnindicator(String where){
		//从指标配置表中读取各指标合法的指标值
		String esql="";
		String list = "";
		
		try{
			esql = "select * from wlan_task_conf"+where;
			ResultSet rs = dd.executeQuery(esql);
			if(rs != null){
				while(rs.next()){
					list = rs.getString("strindicatorvalue");
				}
			}
		}catch (Exception e) {
            e.printStackTrace();
        }
		dd.closeCon();
		return list;
	}
	
	public List<String> returnor(String where){
		//从指标配置表中读取各指标合法的指标值高低位
		String esql="";
		List<String> list = new ArrayList<String>();
		
		try{
			esql = "select * from wlan_task_conf"+where;
			ResultSet rs = dd.executeQuery(esql);
			if(rs != null){
				while(rs.next()){
					list.add(rs.getString("strlessorgreat"));
				}
			}
		}catch (Exception e) {
            e.printStackTrace();
        }
		dd.closeCon();
		return list;
	}
	
	//获取任务名，插入预警表
	public String returntaskname(String where){
		String esql="";
		String list = "";
		
		try{
			esql = "select * from wlan_task_info"+where;
			ResultSet rs = dd.executeQuery(esql);
			if(rs != null){
				while(rs.next()){
					list = rs.getString("strtaskname");
				}
			}
		}catch (Exception e) {
            e.printStackTrace();
        }
		dd.closeCon();
		return list;
	}
	
	//获取AP名，插入预警表
	public String returnAPname(String where){
		String esql="";
		String list = "";
		
		try{
			esql = "select * from RM_DEVICE"+where;
			ResultSet rs = dd.executeQuery(esql);
			if(rs != null){
				while(rs.next()){
					list = rs.getString("device_name");
				}
			}
		}catch (Exception e) {
            e.printStackTrace();
        }
		dd.closeCon();
		return list;
	}
	//获取小区ID，插入预警表
	public String returnCommID(String where){
		String esql="";
		String list = "";
		
		try{
			esql = "select * from WLAN_RESC_COMUNITY"+where;
			ResultSet rs = dd.executeQuery(esql);
			if(rs != null){
				while(rs.next()){
					list = rs.getString("strcommid");
				}
			}
		}catch (Exception e) {
            e.printStackTrace();
        }
		dd.closeCon();
		return list;
	}
	
	//插入预警数据进入预警表
	public void insertWarn(String s1,String s2,String s3,String s4,String s5,String s6,String s7,String s8,String s9,String s10,String s11){
		String strSql = "";
		try {
    		String strTempId = UID.getID();
	        strSql = "INSERT INTO wlan_warnings (strId, strtaskid,strtaskname,strnettype,strcity,strtown,strAPname,strMAC,strcommunityid,strindicatorname,intindicatorvalue,intindicatortestvalue) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";          
	        dd.prepareStatement(strSql);
	        dd.setString(1, strTempId);
	        dd.setString(2, s1);
	        dd.setString(3, s2);
	        dd.setString(4, s3);
	        dd.setString(5, s4);
	        dd.setString(6, s5);
	        dd.setString(7, s6);
	        dd.setString(8, s7);
	        dd.setString(9, s8);
	        dd.setString(10, s9);
	        dd.setString(11, s10);
	        dd.setString(12, s11);
	        if (dd.executeUpdate() > 0) {
	        	System.out.println("*************************************************增加警告数据成功");
	        	dd.closeCon();
	        } 
		} catch (Exception e) {
	        	dd.rollback();
	            e.printStackTrace();
	            dd.closeCon();
		}
		dd.closeCon();
	}
	
	//单独处理每个指标
	public void dealIndicator(String indicator,String taskID,String netType,String city,String town,String MAC,String Lac,String Ci,String itestvalue){
		String where = " where strtestindicator = '"+indicator+"'";
		
		String ivalue = returnindicator(where);//获取指标值
		
		List<String> list2 = returnor(where);//获取指标大于小于或等于
		
		where = " where strtaskid = '"+taskID+"'";
		String taskname = returntaskname(where);//获取任务名
		
		where = " where STRMAC_ADDR = '"+MAC+"'";
		String APname = returnAPname(where);//获取AP名
		
		where = " where strLac = '"+Lac+"' and strCi = '"+Ci+"'";
		String Commid = returnCommID(where);//获取小区ID
		
		//合法指标为<list2.get(0)
		if(Float.parseFloat(list2.get(0))==1){
			if(Float.parseFloat(itestvalue) >= Float.parseFloat(ivalue)){
				//插入警告表
				insertWarn(taskID,taskname,netType,city,town,APname,MAC,Commid,indicator,ivalue,itestvalue);
			}
		}
		
		//合法指标为<=list2.get(0)
		else if(Float.parseFloat(list2.get(0))==2){
			if(Float.parseFloat(itestvalue) > Float.parseFloat(ivalue)){
				//插入警告表
				insertWarn(taskID,taskname,netType,city,town,APname,MAC,Commid,indicator,ivalue,itestvalue);
			}
		}
		
		//合法指标为=list2.get(0)
		else if(Float.parseFloat(list2.get(0))==3){
			if(Float.parseFloat(itestvalue) != Float.parseFloat(ivalue)){
				//插入警告表
				insertWarn(taskID,taskname,netType,city,town,APname,MAC,Commid,indicator,ivalue,itestvalue);
			}
		}
		
		//合法指标为>list2.get(0)
		else if(Float.parseFloat(list2.get(0))==4){
			if(Float.parseFloat(itestvalue) <= Float.parseFloat(ivalue)){
				//插入警告表
				insertWarn(taskID,taskname,netType,city,town,APname,MAC,Commid,indicator,ivalue,itestvalue);
			}
		}
		
		//合法指标为>=list2.get(0)
		else if(Float.parseFloat(list2.get(0))==5){
			if(Float.parseFloat(itestvalue) < Float.parseFloat(ivalue)){
				//插入警告表
				insertWarn(taskID,taskname,netType,city,town,APname,MAC,Commid,indicator,ivalue,itestvalue);
			}
		}
	}
	
	//XML被处理后删除文件
	public void delete(File f){
		File[] FList = f.listFiles();
		for (int i = 0; i < FList.length; i++)
		{
			if (FList[i].isDirectory()==true)
			{
				delete(FList[i]);
			}
			else
			{
				String url=FList[i].getAbsolutePath();
				if(url.contains("xml")){
					File file1 = new File(url); 
					file1.delete(); 
				}
			}
		}
	}
	
	public void read(File f)
	{
		File[] FList = f.listFiles();
		String CELLurl="";
		String taskID="";//存放XML中的任务ID
		String city="";//存放XML中的地市
		String testphone="";//存放XML中的测试人手机
		String Lac="";//存放XML中的小区LAC
		String Ci="";//存放XML中的小区CI
		String nerborCom="";//存放XML中的相邻小区ID
		String HttpAnwerDelay="";//存放XML中的HTTP响应时长
		String MAC="";//存放XML中的AP的MAC地址
		String netType="";//存放XML中的测试网络类型
		String town = "";//存放XML中的区县
		String strrssi = "";//存放信号强度
		//存放XML中的AP关联测试的总次数、成功次数和成功率
		String apTestcount = "";
		String APTestSuccessCount = "";
		String apSucrate = "";
		//存放XML中的WEB认证的总次数、成功次数和成功率
		String webLogincount = "";
		String webLoginsuccount = "";
		String weblograte = "";
		//存放XML中的WEB下线的总次数、成功次数和成功率
		String webOutcount = "";
		String webOutsuccount = "";
		String weboutrate = "";
		//存放XML中的PEAP认证的总次数、成功次数和成功率
		String peapCount = "";
		String peapSuccount = "";
		String peapsucrate = "";
		//存放XML中的PEAP下行的总次数、成功次数和成功率
		String peapOffcount = "";
		String peapOffsuccount = "";
		String peapoffrate = "";
		//存放XML中的PING测试的总次数、成功次数和成功率
		String pingCount = "";
		String pingSuccount = "";
		String pingrate = "";
		//存放XML中的用户隔离测试的总次数、成功次数和成功率
		String userIsolatecount = "";
		String userIsolatesuccount = "";
		String userisorate = "";
		//存放XML中的用户漫游测试的总次数、成功次数和成功率
		String userRoamcount = "";
		String userRoamsuccount = "";
		String userroamrate = "";
		//存放XML中的FTP上行和下行的速率
		String ftpUpspeed = "";
		String ftpDownspeed = "";
		//存放XML中的WEB和PEAP认证时长
		String webDelay = "";
		String peapDelay = "";
		//存放XML中的FTP上行测试的总次数、成功次数和成功率
		String ftpUpcount = "";
		String ftpUpsuccount = "";
		String ftpuprate = "";
		//存放XML中的FTP下行测试的总次数、成功次数和成功率
		String ftpDowncount = "";
		String ftpDownsuccount = "";
		String ftpdownrate = "";
		//存放XML中的AP关联时长
		String aprevaTime = "";
		String pingDelay = "";
		//存放XML中的HTTP请求的总次数、成功次数和成功率
		String httpCallcount = "";
		String httpCallsuccount = "";
		String httpcallrate = "";
		//测试结果上传时间
		String dttime = "";

		String strcarriers = "";
		for (int i = 0; i < FList.length; i++)
		{
			if (FList[i].isDirectory()==true)
			{
				read(FList[i]);
			}
			else
			{
				String url1=FList[i].getAbsolutePath();
				String url=url1.replaceAll("\\\\","\\\\\\\\");
				if(url.contains("CELL")){
					CELLurl = url;
				}
				if(url.contains("xml")){					
					//为测试结果XML，非相邻小区XML则执行读取并插入数据库操作
					if(!url.contains("CELL")){
						
						taskID="";//存放XML中的任务ID
						city="";//存放XML中的地市
						testphone="";//存放XML中的测试人手机
						Lac="";//存放XML中的小区LAC
						Ci="";//存放XML中的小区CI
						nerborCom="";//存放XML中的相邻小区ID
						HttpAnwerDelay="";//存放XML中的HTTP响应时长
						MAC="";//存放XML中的AP的MAC地址
						netType="";//存放XML中的测试网络类型
						town = "";//存放XML中的区县
						strrssi = "";
						//存放XML中的AP关联测试的总次数、成功次数和成功率
						apTestcount = "";
						APTestSuccessCount = "";
						apSucrate = "";
						//存放XML中的WEB认证的总次数、成功次数和成功率
						webLogincount = "";
						webLoginsuccount = "";
						weblograte = "";
						//存放XML中的WEB下线的总次数、成功次数和成功率
						webOutcount = "";
						webOutsuccount = "";
						weboutrate = "";
						//存放XML中的PEAP认证的总次数、成功次数和成功率
						peapCount = "";
						peapSuccount = "";
						peapsucrate = "";
						//存放XML中的PEAP下行的总次数、成功次数和成功率
						peapOffcount = "";
						peapOffsuccount = "";
						peapoffrate = "";
						//存放XML中的PING测试的总次数、成功次数和成功率
						pingCount = "";
						pingSuccount = "";
						pingrate = "";
						//存放XML中的用户隔离测试的总次数、成功次数和成功率
						userIsolatecount = "";
						userIsolatesuccount = "";
						userisorate = "";
						//存放XML中的用户漫游测试的总次数、成功次数和成功率
						userRoamcount = "";
						userRoamsuccount = "";
						userroamrate = "";
						//存放XML中的FTP上行和下行的速率
						ftpUpspeed = "";
						ftpDownspeed = "";
						//存放XML中的WEB和PEAP认证时长
						webDelay = "";
						peapDelay = "";
						//存放XML中的FTP上行测试的总次数、成功次数和成功率
						ftpUpcount = "";
						ftpUpsuccount = "";
						ftpuprate = "";
						//存放XML中的FTP下行测试的总次数、成功次数和成功率
						ftpDowncount = "";
						ftpDownsuccount = "";
						ftpdownrate = "";
						//存放XML中的AP关联时长
						aprevaTime = "";
						pingDelay = "";
						//存放XML中的HTTP请求的总次数、成功次数和成功率
						httpCallcount = "";
						httpCallsuccount = "";
						httpcallrate = "";
						dttime = "";
						//存放XML中的运营商和获取测试时间
						strcarriers = "";
						String[] temp = url.split("_");
						dttime = temp[1].substring(0,4) + "-" + temp[1].substring(4,6) + "-" + temp[1].substring(6,8) + 
						" " + temp[1].substring(8,10) + ":" + temp[1].substring(10,12) + ":" + temp[1].substring(12,14);
						
						if(url.contains("WLAN_"))
							netType = "WLAN";
						else if(url.contains("GSM_"))
							netType = "GSM";
						else if(url.contains("TD_"))
							netType = "TD";
						try{
							DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); 		
							DocumentBuilder builder=factory.newDocumentBuilder();     
							Document doc = builder.parse(url);
							NodeList nl = doc.getElementsByTagName("TestResultInfo");
							if(nl.getLength()>0){
								for (int j=0;j<nl.getLength();j++){
									//获取XML中的任务ID
									if(doc.getElementsByTagName("TaskID").getLength()>0){
										taskID = doc.getElementsByTagName("TaskID").item(j).getFirstChild().getNodeValue();
									}
									//获取XML中的地市名
									if(doc.getElementsByTagName("City").getLength()>0){
										city= doc.getElementsByTagName("City").item(j).getFirstChild().getNodeValue();   
									}
									//获取XML中的区县名
									if(doc.getElementsByTagName("Town").getLength()>0){
										town= doc.getElementsByTagName("Town").item(j).getFirstChild().getNodeValue();   
									}
									//获取XML中的测试人员手机号
									if(doc.getElementsByTagName("TestPhone").getLength()>0){
										testphone = doc.getElementsByTagName("TestPhone").item(j).getFirstChild().getNodeValue();
									}
									//获取XML中的小区LAC
									if(doc.getElementsByTagName("Lac").getLength()>0){
										Lac = doc.getElementsByTagName("Lac").item(j).getFirstChild().getNodeValue();
										//System.out.println("LAC：" + Lac);
									}
									//获取XML中的小区CI
									if(doc.getElementsByTagName("Ci").getLength()>0){
										Ci = doc.getElementsByTagName("Ci").item(j).getFirstChild().getNodeValue();
									}
									//获取XML中的AP的MAC地址
									if(doc.getElementsByTagName("MAC").getLength()>0){
										MAC = doc.getElementsByTagName("MAC").item(j).getFirstChild().getNodeValue();
									}
									//获取XML中的运营商
									if(doc.getElementsByTagName("CommunicationCarriers").getLength()>0){
										strcarriers = doc.getElementsByTagName("CommunicationCarriers").item(j).getFirstChild().getNodeValue();
									}
									//（0）获取XML中的信号强度
									if(doc.getElementsByTagName("RSSI").getLength()>0){
										strrssi = doc.getElementsByTagName("RSSI").item(j).getFirstChild().getNodeValue();
										String indicator = "信号强度";
										dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,strrssi);
									}
									//（1）获取XML中的HTTP响应时长
									if(doc.getElementsByTagName("HttpAnwerDelay").getLength()>0){
										HttpAnwerDelay = doc.getElementsByTagName("HttpAnwerDelay").item(j).getFirstChild().getNodeValue();
										String indicator = "HTTP响应时长";
										dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,HttpAnwerDelay);
									}
									//（2）获取XML中的HTTP请求成功率
									if(doc.getElementsByTagName("HttpCallSuccessRate").getLength()>0){
										httpcallrate = doc.getElementsByTagName("HttpCallSuccessRate").item(j).getFirstChild().getNodeValue();
										String indicator = "HTTP请求成功率";
										dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,httpcallrate);
									}
									if(doc.getElementsByTagName("HttpCallCount").getLength()>0){
										httpCallcount = doc.getElementsByTagName("HttpCallCount").item(j).getFirstChild().getNodeValue();
									}
									if(doc.getElementsByTagName("HttpCallSuccessCount").getLength()>0){
										httpCallsuccount = doc.getElementsByTagName("HttpCallSuccessCount").item(j).getFirstChild().getNodeValue();
									}
									//（3）获取XML中的PING响应时长
									if(doc.getElementsByTagName("PingAvgDelay").getLength()>0){
										pingDelay = doc.getElementsByTagName("PingAvgDelay").item(j).getFirstChild().getNodeValue();
										String indicator = "PING响应时长";
										dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,pingDelay);
									}
									//（4）获取XML中的FTP上行成功率
									if(doc.getElementsByTagName("FTPUpCount").getLength()>0){
										ftpUpcount = doc.getElementsByTagName("FTPUpCount").item(j).getFirstChild().getNodeValue();
									}
									if(doc.getElementsByTagName("FTPUpSuccessCount").getLength()>0){
										ftpUpsuccount = doc.getElementsByTagName("FTPUpSuccessCount").item(j).getFirstChild().getNodeValue();
										if(Float.parseFloat(ftpUpcount)!=0.0){
											ftpuprate = String.valueOf(Float.parseFloat(ftpUpsuccount)/Float.parseFloat(ftpUpcount));
											String indicator = "FTP上行成功率";
											dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,ftpuprate);
										}
									}
									//（5）获取XML中的FTP下行成功率
									if(doc.getElementsByTagName("FTPDownCount").getLength()>0){
										ftpDowncount = doc.getElementsByTagName("FTPDownCount").item(j).getFirstChild().getNodeValue();
									}
									if(doc.getElementsByTagName("FTPDownSuccessCount").getLength()>0){
										ftpDownsuccount = doc.getElementsByTagName("FTPDownSuccessCount").item(j).getFirstChild().getNodeValue();
										if(Float.parseFloat(ftpDowncount)!=0){
											ftpdownrate = String.valueOf(Float.parseFloat(ftpDownsuccount)/Float.parseFloat(ftpDowncount));
											String indicator = "FTP下行成功率";
											dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,ftpdownrate);
										}
									}
									//（6）获取XML中的AP关联时长
									if(doc.getElementsByTagName("RelevanceAPAvgTime").getLength()>0){
										aprevaTime = doc.getElementsByTagName("RelevanceAPAvgTime").item(j).getFirstChild().getNodeValue();
										String indicator = "AP关联时长";
										dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,aprevaTime);
									}
									//（7）获取XML中的AP关联成功率
									if(doc.getElementsByTagName("APTestCount").getLength()>0){
										apTestcount = doc.getElementsByTagName("APTestCount").item(j).getFirstChild().getNodeValue();
									}
									if(doc.getElementsByTagName("APTestSuccessCount").getLength()>0){
										APTestSuccessCount = doc.getElementsByTagName("APTestSuccessCount").item(j).getFirstChild().getNodeValue();
										if(Float.parseFloat(apTestcount)!=0){
											apSucrate = String.valueOf(Float.parseFloat(APTestSuccessCount)/Float.parseFloat(apTestcount));
											String indicator = "AP关联成功率";
											dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,apSucrate);
										}
									}
									//（8）获取XML中的WEB认证成功率
									if(doc.getElementsByTagName("WebLoginCount").getLength()>0){
										webLogincount = doc.getElementsByTagName("WebLoginCount").item(j).getFirstChild().getNodeValue();
									}
									if(doc.getElementsByTagName("WebLoginSuccessCount").getLength()>0){
										webLoginsuccount = doc.getElementsByTagName("WebLoginSuccessCount").item(j).getFirstChild().getNodeValue();
										if(Float.parseFloat(webLogincount)!=0){
											weblograte = String.valueOf(Float.parseFloat(webLoginsuccount)/Float.parseFloat(webLogincount));
											String indicator = "WEB认证成功率";
											dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,apSucrate);
										}
									}
									//（9）获取XML中的WEB下线成功率
									if(doc.getElementsByTagName("WebOutCount").getLength()>0){
										webOutcount = doc.getElementsByTagName("WebOutCount").item(j).getFirstChild().getNodeValue();
									}
									if(doc.getElementsByTagName("WebOutSuccessCount").getLength()>0){
										webOutsuccount = doc.getElementsByTagName("WebOutSuccessCount").item(j).getFirstChild().getNodeValue();
										if(Float.parseFloat(webOutcount)!=0){
											weboutrate = String.valueOf(Float.parseFloat(webOutsuccount)/Float.parseFloat(webOutcount));
											String indicator = "WEB下线成功率";
											dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,apSucrate);
										}
									}
									//（10）获取XML中的PEAP认证成功率
									if(doc.getElementsByTagName("PeapCount").getLength()>0){
										peapCount = doc.getElementsByTagName("PeapCount").item(j).getFirstChild().getNodeValue();
									}
									if(doc.getElementsByTagName("PeapSuccessCount").getLength()>0){
										peapSuccount = doc.getElementsByTagName("PeapSuccessCount").item(j).getFirstChild().getNodeValue();
										if(Float.parseFloat(peapCount)!=0){
											peapsucrate = String.valueOf(Float.parseFloat(peapSuccount)/Float.parseFloat(peapCount));
											String indicator = "PEAP认证成功率";
											dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,peapsucrate);
										}
									}
									//（11）获取XML中PEAP下线成功率
									if(doc.getElementsByTagName("PeapOffCount").getLength()>0){
										peapOffcount = doc.getElementsByTagName("PeapOffCount").item(j).getFirstChild().getNodeValue();
									}
									if(doc.getElementsByTagName("PeapOffSuccessCount").getLength()>0){
										peapOffsuccount = doc.getElementsByTagName("PeapOffSuccessCount").item(j).getFirstChild().getNodeValue();
										if(Float.parseFloat(peapOffcount)!=0.0){
											peapoffrate = String.valueOf(Float.parseFloat(peapOffsuccount)/Float.parseFloat(peapOffcount));
											String indicator = "PEAP下线成功率";
											dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,peapoffrate);
										}
									}
									//（12）获取XML中PING成功率
									if(doc.getElementsByTagName("PingCount").getLength()>0){
										pingCount = doc.getElementsByTagName("PingCount").item(j).getFirstChild().getNodeValue();
									}
									if(doc.getElementsByTagName("PingSuccessCount").getLength()>0){
										pingSuccount = doc.getElementsByTagName("PingSuccessCount").item(j).getFirstChild().getNodeValue();
										if(Float.parseFloat(pingCount)!=0){
											pingrate = String.valueOf(Float.parseFloat(pingSuccount)/Float.parseFloat(pingCount));
											String indicator = "PING成功率";
											dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,pingrate);
										}
									}
									//（13）获取XML中用户隔离成功率
									if(doc.getElementsByTagName("UserIsolateCount").getLength()>0){
										userIsolatecount = doc.getElementsByTagName("UserIsolateCount").item(j).getFirstChild().getNodeValue();
									}
									if(doc.getElementsByTagName("UserIsolateSuccessCount").getLength()>0){
										userIsolatesuccount = doc.getElementsByTagName("UserIsolateSuccessCount").item(j).getFirstChild().getNodeValue();
										if(Float.parseFloat(userIsolatecount)!=0){
											userisorate = String.valueOf(Float.parseFloat(userIsolatesuccount)/Float.parseFloat(userIsolatecount));
											String indicator = "用户隔离成功率";
											dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,userisorate);
										}
									}
									//（14）获取XML中用户漫游成功率
									if(doc.getElementsByTagName("UserRoamCount").getLength()>0){
										userRoamcount = doc.getElementsByTagName("UserRoamCount").item(j).getFirstChild().getNodeValue();
									}
									if(doc.getElementsByTagName("UserRoamSuccessCount").getLength()>0){
										userRoamsuccount = doc.getElementsByTagName("UserRoamSuccessCount").item(j).getFirstChild().getNodeValue();
										if(Float.parseFloat(userRoamcount)!=0){
											userroamrate = String.valueOf(Float.parseFloat(userRoamsuccount)/Float.parseFloat(userRoamcount));
											String indicator = "用户漫游成功率";
											dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,userroamrate);
										}
									}
									//(15)获取XML中FTP上行速率
									if(doc.getElementsByTagName("FTPUpAvgSuccessRate").getLength()>0){
										ftpUpspeed = doc.getElementsByTagName("FTPUpAvgSuccessRate").item(j).getFirstChild().getNodeValue();
										String indicator = "FTP上行速率";
										dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,ftpUpspeed);
									}
									//（16）获取XML中FTP下行速率
									if(doc.getElementsByTagName("FTPDownAvgSuccessRate").getLength()>0){
										ftpDownspeed = doc.getElementsByTagName("FTPDownAvgSuccessRate").item(j).getFirstChild().getNodeValue();
										String indicator = "FTP下行速率";
										dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,ftpDownspeed);
									}
									//（17）获取XML中WEB认证时长
									if(doc.getElementsByTagName("WebDelay").getLength()>0){
										webDelay = doc.getElementsByTagName("WebDelay").item(j).getFirstChild().getNodeValue();
										String indicator = "WEB认证时长";
										dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,webDelay);
									}
									//（18）获取XML中PEAP认证时长
									if(doc.getElementsByTagName("PeapDelay").getLength()>0){
										peapDelay = doc.getElementsByTagName("PeapDelay").item(j).getFirstChild().getNodeValue();
										String indicator = "PEAP认证时长";
										dealIndicator(indicator,taskID,netType,city,town,MAC,Lac,Ci,peapDelay);
									}
								}
							}					
						}catch(Exception e){
							e.printStackTrace();
						}
						
						String strSql="";
						String strTableName="wlan_test_result";
						String strCommid = "";
						
						try{
							strSql = "select * from wlan_resc_comunity where strLac = '"+Lac+"' and strCi = '"+Ci+"'";
							ResultSet rs = dd.executeQuery(strSql);
							if(rs != null){
								while(rs.next()){
									strCommid = rs.getString("strcommid");
								}
							}
						}catch (Exception e) {
				            e.printStackTrace();
				        }
						
						try {
		            		String strTempId = UID.getID();
					        strSql = "INSERT INTO " + strTableName + " (strId, strtaskid,strcommunityid,intap_relevacy_sucrate,intap_relevacy_delay," +
					        		"intweb_auth_sucrate,intweb_off_sucrate,intpeap_auth_sucrate,intpeap_off_sucrate,inthttp_req_sucrate,intping_sucrate," +
					        		"intftp_up_sucrate,intftp_down_sucrate,intuser_seg_sucrate,intuser_roam_sucrate,intweb_up_delay," +
					        		"intpeap_up_delay,inthttp_resp_delay,intftp_up_speed,intftp_down_speed,intap_corr_suc_counts,intap_corr_total_counts," +
					        		"intweb_auth_suc_counts,intweb_auth_total_counts,intweb_off_suc_counts,intweb_off_total_counts,intpeap_auth_suc_counts," +
					        		"intpeap_auth_total_counts,intpeap_off_suc_counts,intpeap_off_total_counts,inthttp_req_suc_counts,inthttp_req_total_counts," +
					        		"intftp_up_suc_counts,intftp_up_total_counts,intftp_down_suc_counts,intftp_down_total_counts,intuser_seg_suc_counts,intuser_seg_total_counts," +
					        		"intuser_roam_suc_counts,intuser_roam_total_counts,strapmac,strnettype,dtcreatdate,intping_delay,intping_total_counts,intping_suc_counts,intrssi,strcarriers) VALUES " +
					        		"(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,to_date(?,'yyyy-MM-dd hh24:mi:ss'),?,?,?,?,?)"; 
					        //说明：strSql目前字段48个，而wlan_test_result共有字段51个，其中字段strneicommunityid由后面程序进行更新，字段strtext（合格与否）暂无合适判断方法
					        //字段intweb_down_delay在数据库中存在，但是XML只有WEB_DELAY字段，故取数据库中intweb_up_delay字段为其值
					        dd.prepareStatement(strSql);
					        dd.setString(1, strTempId);
					        dd.setString(2, taskID);
					        dd.setString(3, strCommid);
					        dd.setString(4, apSucrate);
					        dd.setString(5, aprevaTime);
					        dd.setString(6, weblograte);
					        dd.setString(7, weboutrate);
					        dd.setString(8, peapsucrate);
					        dd.setString(9, peapoffrate);
					        dd.setString(10, httpcallrate);
					        dd.setString(11, pingrate);
					        dd.setString(12, ftpuprate);
					        dd.setString(13, ftpdownrate);
					        dd.setString(14, userisorate);
					        dd.setString(15, userroamrate);
					        dd.setString(16, webDelay);
					        dd.setString(17, peapDelay);
					        dd.setString(18, HttpAnwerDelay);
					        dd.setString(19, ftpUpspeed);
					        dd.setString(20, ftpDownspeed);
					        dd.setString(21, APTestSuccessCount);
					        dd.setString(22, apTestcount);
					        dd.setString(23, webLoginsuccount);
					        dd.setString(24, webLogincount);
					        dd.setString(25, webOutsuccount);
					        dd.setString(26, webOutcount);
					        dd.setString(27, peapSuccount);
					        dd.setString(28, peapCount);
					        dd.setString(29, peapOffsuccount);
					        dd.setString(30, peapOffcount);
					        dd.setString(31, httpCallsuccount);
					        dd.setString(32, httpCallcount);
					        dd.setString(33, ftpUpsuccount);
					        dd.setString(34, ftpUpcount);
					        dd.setString(35, ftpDownsuccount);
					        dd.setString(36, ftpDowncount);
					        dd.setString(37, userIsolatesuccount);
					        dd.setString(38, userIsolatecount);
					        dd.setString(39, userRoamsuccount);
					        dd.setString(40, userRoamcount);
					        dd.setString(41, MAC);
					        dd.setString(42, netType);
					        dd.setString(43, dttime);
					        dd.setString(44, pingDelay);
					        dd.setString(45, pingCount);
					        dd.setString(46, pingSuccount);
					        dd.setString(47, strrssi);
					        dd.setString(48, strcarriers);
					        
					        if (dd.executeUpdate() > 0) {
					        	System.out.println("*************************************************测试结果入库成功！");
					        	dd.closeCon();
					        } 
						} catch (Exception e) {
					            e.printStackTrace();
					            dd.closeCon();
						}
					}
				}
			}
			//一个文件夹遍历结束后，再将该文件夹中CELL的XML数据传入数据库，该文件存储的相邻小区信息，因而通过该文件
			//获取相邻小区号，然后更新结果表中的各项测试中的相邻小区号
			if(CELLurl!=""){
				try{
					DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); 		
					DocumentBuilder builder=factory.newDocumentBuilder();     
					Document doc = builder.parse(CELLurl);
					NodeList nk = doc.getElementsByTagName("TESTRESULTINFO");
					if(nk.getLength()>0){
						nerborCom="";
						String LAC="";
						String CI="";
						String tempnerborCom = "";
						for (int j=0;j<nk.getLength();j++){
							if(doc.getElementsByTagName("LAC").getLength()>0){
								LAC = doc.getElementsByTagName("LAC").item(j).getFirstChild().getNodeValue();
							}
							if(doc.getElementsByTagName("CI").getLength()>0){
								CI = doc.getElementsByTagName("CI").item(j).getFirstChild().getNodeValue();
							}
							String sql="";
							
							try{
								sql = "select * from wlan_resc_comunity where strLac = '"+LAC+"' and strCi = '"+CI+"'";
								ResultSet rs = dd.executeQuery(sql);
								if(rs != null){
									while(rs.next()){		
										tempnerborCom=tempnerborCom+rs.getString("strcommid")+",";
										nerborCom = tempnerborCom.substring(0, tempnerborCom.length()-1);
									}
								}
							}catch (Exception e) {
					            e.printStackTrace();
					        }
						}
					}
				}catch(Exception e){
					e.printStackTrace();
				}			
				
				String strSql="";
				String strTableName="wlan_test_result";
				
				try {
			        strSql = "update " + strTableName + " set strneicommunityid = '"+nerborCom+"' where strtaskid = '"+taskID+"'";
			        if (dd.executeUpdate(strSql) > 0) {
			        	System.out.println("*************************************************相邻小区信息更新成功！");
			        } 
				} catch (Exception e) {
			            e.printStackTrace();
				}	
			}
		}
		dd.closeCon();
	}
}